#!/usr/bin
# -*- coding: utf-8 -*-

import mod_parameters as params
import mod_material as mat



TCI = params.PARAMS["testConstructorsInputs"]



# ==============================================================================
class Section():
    PARAMS = None
    TYPE = None

    def __init__(self, uId, parameters, material):
        if TCI:
            self.testInputs(uId, parameters, material)
        self.uId = uId
        self.params = parameters
        self.mat = material

    def testInputs(self, uId, parameters, material):
        if not isinstance(uId, str):
            raise ValueError
        if not isinstance(parameters, dict):
            raise ValueError
        keys = parameters.keys()
        keys.sort()
        requiredKeys = self.PARAMS.keys()
        requiredKeys.sort()
        if not keys == requiredKeys:
            raise ValueError
        for key, typ in self.PARAMS.items():
            if not isinstance(parameters[key], typ):
                raise ValueError
        if not isinstance(material, mat.Material):
            raise ValueError

    def __str__(self):
        a = "Section " + self.TYPE + ":\n"
        a += "- user id: " + str(self.uId) + "\n"
        a += "- parameters:"
        for key, val in self.params.items():
            a += "\n  - " + key + ": " + str(val)
        a += "\n- material:\n" + str(self.mat)
        return a



# ==============================================================================
class HomogeneousShellSection(Section):
    """ Shell section for shell element
    """
    PARAMS = {"thickness": float}
    TYPE = "HomogeneousShellSection"

    def __init__(self, uId, parameters, material):
        Section.__init__(self, uId, parameters, material)


# ==============================================================================
if __name__ == "__main__":
    myMaterial = mat.IsotropicElasticMaterial("Aluminium", {"E":70000.0,
                                                            "nu":0.25})
    mySection = HomogeneousShellSection("Plaque isotrope", {"thickness":2.0},
                                        myMaterial)
    print mySection
